<template>
  <div class="content-main">
    <div class="content-edit">
      <el-button type="primary" icon="el-icon-plus" @click="add" :disabled="total >= 100"
        >添加</el-button
      >
      <el-button icon="el-icon-download" v-if="false">下载</el-button>
    </div>
    <table-area
      :loading="loading"
      :page="page"
      :size="size"
      :total="total"
      :list="list"
      @current-change="currentChange"
      @size-change="sizeChange"
      @edit="edit"
      @del="del"
      @check="check"
    />
    <edit-modal :show="editModal" :info="editModalInfo" @close="close" />
    <table-modal :show="tableModal" :info="tableModalInfo" @close="tableClose" />
  </div>
</template>

<script lang="ts">
import { Component } from "vue-property-decorator";
// lib
import PageTableVm from "@/public/base/PageTableVm";
// components & widgets
import TableArea from "./TableArea.vue";
import EditModal from "./EditModal.vue";
import TableModal from "./TableModal.vue";
// config
// script & public
import logUtils from "@/utils/logUtils";
// controller & service
import { delDeptService, getDeptPageService } from "@/biz/dept/service";
// interface
import { DeptDto } from "@/biz/dept/model";
// 其它

@Component({
  components: {
    TableArea,
    EditModal,
    TableModal,
  },
})
export default class SystemMenu extends PageTableVm {
  tableModalInfo = null;
  tableModal = false;
  mounted() {
    // this.getPage();
  }
  check(row: any) {
    this.tableModalInfo = row;
    this.tableModal = true;
  }
  tableClose() {
    this.tableModal = false;
  }
  async getPage() {
    // 调用服务
    this.loading = true;
    const result = await getDeptPageService({
      pageNum: this.page,
      pageSize: this.size,
    });
    this.loading = false;
    if (result.payload) {
      this.list = result.payload.list;
      this.total = result.payload.total;
    }
    // 失败和异常
  }
  async del(row: DeptDto) {
    const result = await delDeptService(row.deptId);
    // 成功
    if (result.payload) {
      this.$message.success("删除成功");
      this.getPage();
    }
    // 失败和异常
  }
}
</script>

<style lang="scss"></style>
